<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;

class Payorder extends Model
{
    //
    protected $table = 'payorders';
    protected $keyType = 'string';
    protected $fillable = [
        'orderid', 'tradeno', 'createtime','userid','price','goodname','goodid','payact',"stime","etime"
    ];
    function insertguestorder($custom)
    {
        // TODO: Implement insertguestorder() method.
        $curdate   = date('Y-m-d H:i:s', time());
        $orderdata = array(
//            "orderid"    => Uuid::uuid1(),
//            "tradeno"    => $custom['tradeno'],
//            "createtime" => time(),
//            "userid"     => $custom['userid'],
//            "goodid"     => $custom['goodid'],
//            "stime"      => $curdate,//插入下载有效期的开始时间
//            "etime"      => date("Y-m-d", strtotime("+1 months", strtotime($curdate)))//插入下载有效期的结束时间
            "orderid"    => Uuid::uuid1(),
            "tradeno"    => $custom['tradeno'],
            "createtime" => date('Y-m-d H:i:s',time()),
            "userid"     => $custom['userid'],
            "goodid"     => $custom['goodid'],
            "payact"     => $custom['payact'],
            "price"      => $custom['price'],//订单价格
            "goodname"   => $custom['goodname'],//商品名称
            "stime"      => $curdate,//插入下载有效期的开始时间
            "etime"      => date("Y-m-d", strtotime("+1 months", strtotime($curdate)))//插入下载有效期的结束时间
        );
        //dd($orderdata);
        //插入订单，此处需要加上事物，处理订单插入失败时候，需要回滚的一些情况
         return self::create($orderdata);
    }

    /**
     * 订单列表
     */
    public function payorderlist(){
        return Payorder::paginate(20);
    }
}
